import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/pending_approval_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class PendingApprovalPage extends StatefulWidget {
  @override
  PendingApprovalPageState createState() => PendingApprovalPageState();
}

class PendingApprovalPageState extends State<PendingApprovalPage> {
  bool show = true;
  List<PendingApprovalData> datas = [];

  @override
  void initState() {
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
          backgroundColor: Color(0XFF00A5F1),
          title: Text(
            "待审批预约",
            style: TextStyle(fontSize: 18),
          ),
          actions: <Widget>[
            new IconButton(
              // action button
              padding: EdgeInsets.only(),
              iconSize: 22,
              icon: new Icon(IconData(0xe617, fontFamily: "wuIconFont")),
              onPressed: () {
                Navigator.pushNamed(context, "/search");
              },
            )
          ],
          elevation: 0,
          centerTitle: true,
        ),
        body: LoadBuilder(
          builder: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return ItemDetails(datas.elementAt(index));
              },
              separatorBuilder: (BuildContext context, int index) {
                return Divider(
                  color: Color(0XFFEEEEEE),
                  height: 1,
                );
              },
              itemCount: datas.length),
          visibility: show,
        ));
  }

  Future getData() async {
    show = true;
    InternetAPI.getInstance()
        .get("OMS/MiWarehouseOutTask/GetAllMiWarehouseOutTask", (data) {
      setState(() {
        show = false;
        datas = PendingApprovalEntity.fromJson(data).datas;
      });
    }, params: {
      "userid": DataSingleton().Data.id,
      "operaterUserId": DataSingleton().Data.id,
      "tenantId": DataSingleton().Data.tenantId,
      "warehouseid": DataSingleton().warehouseChoice.id,
      "operaterUserName": DataSingleton().Data.username,
      "taskState":"10",
      "warehouseouttype":"20",
      "pageNo": -1,
    });
  }
}

class ItemDetails extends StatelessWidget {
  PendingApprovalData _data;

  ItemDetails(this._data);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.all(12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          ItemText("任务编号：${_data.taskno}", 0),
          ItemText("领料单号：${_data.erpno}", 6),
          ItemText("需求单位：${_data.department}", 6),
          ItemText("目的地：${_data.destination}", 6),
          ItemText("创建时间：${_data.creationTime}", 6),
        ],
      ),
    );
  }
}

class ItemText extends StatelessWidget {
  String text;
  double top;

  ItemText(this.text, this.top);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: top),
      child: Text(
        text,
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(color: Color(0xff646464), fontSize: 14),
      ),
    );
  }
}
